package ui.table;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JTable;

import data.Event;

public class TableButtonListener extends MouseAdapter
{
	private final JTable table;
	public TableButtonListener(JTable table) {
		this.table = table;
	}

	public void mousePressed(MouseEvent e) {
		super.mousePressed(e);
		int column = table.getColumnModel().getColumnIndexAtX(e.getX());
		int row = e.getY()/table.getRowHeight(); 
		if (row < table.getRowCount() && row >= 0 && column < table.getColumnCount() && column >= 0) {
		    Object value = table.getValueAt(row, column);
		    if (value instanceof EventButton) {
		    	EventButton button = (EventButton) value;
		    	button.doClick();
//		    	table.setValueAt(button, row, column);
//		    	String command;
//		    	if (column == 0) {
//		    		command = "star";
//		    	} else {
//		    		command = "tick";
//		    	}
//		    	command += " " + ((Event)table.getValueAt(row, 1)).getId();
		    	//System.out.println(command);
		    	//table.firePropertyChange("userCommand", null, command);
		    }
		}
	}
}

